package com.eogo.item.service.impl;

import com.eogo.egexception.EgException;
import com.eogo.egexception.status.EgExceptionStatus;
import com.eogo.item.mapper.CategoryMapper;
import com.eogo.item.pojo.Category;
import com.eogo.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public List<Category> queryCategoryByPid(Long pid) {
        //查询条件。mapper会把对象中的非空属性作为条件
       Category category = new  Category();
       category.setParentId(pid);
       List<Category> list = categoryMapper.select(category);
       //判断结果
      /* if(CollectionUtils.isEmpty(list)){
            throw new EgException(EgExceptionStatus.CATEGORY_NOT_FOUND);
       }*/
       return list;
    }

    @Override
    public void insertCategory(Category category) {
        categoryMapper.insert(category);
    }

    @Override
    public Category queryCategoryById(Long id) {
        return categoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateCategory(Category category) {
        categoryMapper.updateByPrimaryKey(category);
    }
}
